﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NHibernate;
using SAKS.Models;

namespace SAKS.Services.Query
{
    class PagedMessageReceivedSearch : PagedQueryOverBase<MessageReceived>
    {
        public PagedMessageReceivedSearch(ISession session):base(session){}
        public string To { get; set; }
        public bool HasRead { get; set; }
        protected override IQueryOver<MessageReceived, MessageReceived> GetQuery()
        {
            var query = Session.QueryOver<MessageReceived>();
            if (!string.IsNullOrEmpty(To))
                query = query.Where( m => m.ToName == To);
            query = query.Where( m => m.HasRead == HasRead);
            query = query.OrderBy(m => m.Date).Desc;
            return query;
        }
    }
}
